<?php
/**
 *  StorableObject class unit tests
 *
 *  @author Jean-Lou Dupont
 *  @version @@package-version@@
 */

require_once 'PHPUnit/Framework.php';
require_once 'web-bloks/StorableClass/StorableClass.php';
require_once 'UnitTestClass.php';

class UnitTest extends PHPUnit_Framework_TestCase
{

    protected function setUp()
    {
    }
 
    public function testToXML()
    {
		$obj = new testclass;
		
		$xmlstr = $obj->toXML();
		
		#echo "\n ${xmlstr}\n";
		
        // Assert that the size of the Array fixture is 1.
        $this->assertEquals(true, is_string( $xmlstr ));
    }

	public function testFromXML()
	{
		$obj = new testclass;		
		$xmlstr = $obj->toXML();
		
		#var_dump( $xmlstr );
		
		$obj2 = WB_StorableClass::fromXML( $xmlstr );	
		
		#var_dump($obj2);
		
		$this->assertEquals( true, $obj2 instanceof testclass );	
	}
	
	public function testCompare()
	{
		$obj = new testclass;		
		$xmlstr = $obj->toXML();

		$obj2 = WB_StorableClass::fromXML( $xmlstr );	
		
#		var_dump( $this->obj );
#		var_dump( $obj2 );
		
		$this->assertEquals( true, $obj2 == $obj );			
	}
	
	public function testArraySingle()
	{
		$obj = new testclass2;		
		$xmlstr = $obj->toXML();
		$obj2 = WB_StorableClass::fromXML( $xmlstr );
		$this->assertEquals( true, $obj2 == $obj );				
	}	
	public function testException()
	{
		$xmlstr = 'invalid xml string';
		$result = false;
		$exception = null;
		try{
			$obj2 = WB_StorableClass::fromXML( $xmlstr );
		}
		catch( Exception $e )
		{
			$result = true;
			$exception = $e;
		}
		$this->assertEquals( true, $result );
	}
	public function testHiddenProperty()
	{
		$obj = new testclass;
		$obj->_hiddenProperty = 'HIDDEN';
		
		$xmlstr = $obj->toXML();

		$obj2 = WB_StorableClass::fromXML( $xmlstr );	
		$this->assertEquals( true, $obj2->_hiddenProperty == TestClass::hiddenProperty );		
	}	
}